package edu.berkeley.cs160.dereknelson.prog2;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;

public class PainterSettings extends Activity {

	private RadioGroup mode;
	private RadioGroup color;
	private SeekBar brushSize;
	private Button btnDone;
	
	private OnClickListener onDoneClick = new OnClickListener() {
		public void onClick(View v) {
			String modeSetting = "";
			String colorSetting = "";
			int sizeSetting;
			
			switch (color.getCheckedRadioButtonId()) {
			case R.id.radioGray:
				colorSetting = "gray";
				break;
			case R.id.radioBlue:
				colorSetting = "blue";
				break;
			case R.id.radioRed:
				colorSetting = "red";
				break;
			}
			
			switch (mode.getCheckedRadioButtonId()) {
			case R.id.radioDraw:
				modeSetting = "draw";
				break;
			case R.id.radioErase:
				modeSetting = "erase";
				break;
			}
			
			sizeSetting = brushSize.getProgress();
			
			// Gather values and finish
			Intent settings = new Intent();
			settings.putExtra("mode", modeSetting);
			settings.putExtra("size", String.valueOf(sizeSetting));
			settings.putExtra("color", colorSetting);
			setResult(RESULT_OK, settings);
			finish();
		}
		
	};
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.settings);
        
        mode = (RadioGroup)findViewById(R.id.modeGroup);
        color = (RadioGroup)findViewById(R.id.colorGroup);
        brushSize = (SeekBar)findViewById(R.id.seekSize);
        
        btnDone = (Button)findViewById(R.id.btnDone);
        btnDone.setOnClickListener(onDoneClick);
        
        // Default values
        ((RadioButton)findViewById(R.id.radioDraw)).setChecked(true);
        ((RadioButton)findViewById(R.id.radioGray)).setChecked(true);
        ((SeekBar)findViewById(R.id.seekSize)).setProgress(20);
    }
}